//
//  NSDecimalNumber+YTAdd.m
//  Elife
//
//  Created by 拓客营 on 2022/7/8.
//

#import "NSDecimalNumber+YTAdd.h"

@implementation NSDecimalNumber (YTAdd)

+(BOOL)IsEmptyOrZero:(NSDecimalNumber *)money {
    if ([money isEqualToNumber:NSDecimalNumber.zero]) {
        return YES;
    }
    if (!money) {
        return YES;
    }
    return NO;
}

-(NSDecimalNumber *)addNumber:(NSDecimalNumber *)number {
    
    NSDecimalNumber *firstNum = self;
    NSDecimalNumber *secondNum = number;
    
    if (!firstNum) {
        firstNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    if (!number) {
        secondNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    return [firstNum decimalNumberByAdding:secondNum];
}

-(NSDecimalNumber *)reduceNumber:(NSDecimalNumber *)number {
    
    NSDecimalNumber *firstNum = self;
    NSDecimalNumber *secondNum = number;
    
    if (!firstNum) {
        firstNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    if (!number) {
        secondNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    return [firstNum decimalNumberBySubtracting:secondNum];
}

-(NSDecimalNumber *)multiplyNumber:(NSDecimalNumber *)number {
    
    NSDecimalNumber *firstNum = self;
    NSDecimalNumber *secondNum = number;
    
    if (!firstNum) {
        firstNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    if (!number) {
        secondNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    return [firstNum decimalNumberByMultiplyingBy:secondNum];
}

-(NSDecimalNumber *)dividingNumber:(NSDecimalNumber *)number {
    
    NSDecimalNumber *firstNum = self;
    NSDecimalNumber *secondNum = number;
    
    if (!firstNum) {
        firstNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    if (!number) {
        secondNum = [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    return [firstNum decimalNumberByDividingBy:secondNum];
}

+(NSDecimalNumber *)numberCount:(NSString *)count {
    
    if (!count) {
        return [NSDecimalNumber decimalNumberWithString:@"0"];
    }
    
    return [NSDecimalNumber decimalNumberWithString:count];
}

@end
